package com.utils.httpclient;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class testHttpClient {
	

	public static void main(String[] args) {
		HttpClientGet.createDefaultHttpClient();
//		Map<String, String> header = new HashMap<String, String>();
//		header.put("Cookie",cookie);
//		HttpClientGet.setHeader(header);
		String contentHTML = HttpClientGet.sendHttpGet("https://www.doooor.com/forum.php?mod=forumdisplay&fid=111&sortall=1&sortall=1&filter=sortall&page=1");
		System.out.println(contentHTML);
	}
	private Map<String, String> baisiHot(Map<String, String> hotMap) {
		for (int i = 1; i < 3; i++) {
			String contentHTML = getContent("http","UUID=3123",i);
			System.out.println(contentHTML);
		}
		return hotMap;
	}

	private String getContent(String url,String cookie, int i) {
		HttpClientGet.createDefaultHttpClient();
		Map<String, String> header = new HashMap<String, String>();
		header.put("Cookie",cookie);
		HttpClientGet.setHeader(header);
		if(i==0) return null;
		else if(i>0) url = url.replace("(*)", String.valueOf(i));
		String contentHTML = HttpClientGet.sendHttpGet(url);
		return contentHTML;
	}
	
	/** 
     * 这个例子展示了如何执行请求包含一个多部分编码的实体 
     * 模拟表单提交 
     * @throws IOException  
     */  
    /*public static void main(String[] args) throws IOException {  
        CloseableHttpClient httpClient = HttpClients.createDefault();  
        try{  
            //要上传的文件的路径  
            String filePath = "D:\\my_shutdown.log";  
            //把一个普通参数和文件上传给下面这个地址    是一个servlet  
            HttpPost httpPost = new HttpPost("http://localhost:80/testjs/servlet/UploadServlet");  
           
            String a = "";
            InputStream in = new ByteArrayInputStream(a.getBytes("UTF-8"));            //把文件转换成流对象FileBody  
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();  
            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);  
            builder.addBinaryBody("uploadFile", in, ContentType.create("multipart/form-data"), "text01.txt");  

            FileBody bin = new FileBody(new File(filePath));  
            //普通字段  重新设置了编码方式  
            StringBody comment = new StringBody("这里是一个评论", ContentType.create("text/plain", Consts.UTF_8));  
            //StringBody comment = new StringBody("这里是一个评论", ContentType.TEXT_PLAIN);  
              
            StringBody name = new StringBody("王五", ContentType.create("text/plain", Consts.UTF_8));  
            StringBody password = new StringBody("123456", ContentType.create("text/plain", Consts.UTF_8));  
            
            //4)构建请求参数 普通表单项  
            StringBody stringBody = new StringBody("12",ContentType.MULTIPART_FORM_DATA); 
            
            HttpEntity reqEntity = MultipartEntityBuilder.create()  
            .addPart("media", bin)//相当于<input type="file" name="media"/>  
            .addPart("comment", comment)  
            .addPart("name", name)//相当于<input type="text" name="name" value=name>  
            .addPart("password", password)  
            .build();  
              
            httpPost.setEntity(reqEntity);  
              
            System.out.println("发起请求的页面地址 " + httpPost.getRequestLine());  
            //发起请求   并返回请求的响应  
            CloseableHttpResponse response = httpClient.execute(httpPost);  
            try {  
                System.out.println("----------------------------------------");  
                //打印响应状态  
                System.out.println(response.getStatusLine());  
                //获取响应对象  
                HttpEntity resEntity = response.getEntity();  
                if (resEntity != null) {  
                    //打印响应长度  
                    System.out.println("Response content length: " + resEntity.getContentLength());  
                    //打印响应内容  
                    System.out.println(EntityUtils.toString(resEntity,Charset.forName("UTF-8")));  
                }  
                //销毁  
                EntityUtils.consume(resEntity);  
            } finally {  
                response.close();  
            }  
        }finally{  
            httpClient.close();  
        }  
    } */
}
